package com.duoketech.service.web.custom;
import com.duoketech.service.AbstractService;
import com.duoketech.model.custom.Customization;
import com.duoketech.exception.ValidateException;
import com.duoketech.utils.search.QueryConstructor;
import com.duoketech.utils.validator.Validator;
import com.duoketech.utils.validator.rules.string.StringLengthBetween;
import com.duoketech.utils.validator.rules.string.StringMustBeRequired;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Model;

public class CustomizationService extends AbstractService{
    public static CustomizationService ME = new CustomizationService();

    @Override
    public void validatorUpdate(Model<?> model, Kv kv) throws ValidateException {
        validatorAdd(model,kv);
    }

    @Override
    public void validatorAdd(Model<?> model, Kv kv) throws ValidateException {

        Validator validator = new Validator();
        validator.addRule(new StringMustBeRequired(model.getStr(Customization.ID),"项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Customization.ID),"项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Customization.MOBILE),"联系电话项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Customization.MOBILE),"联系电话项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Customization.NAME),"联系人项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Customization.NAME),"联系人项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Customization.CONTENT),"定制内容项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Customization.CONTENT),"定制内容项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Customization.SOURCE),"来自谁项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Customization.SOURCE),"来自谁项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Customization.TO),"找谁定制项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Customization.TO),"找谁定制项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Customization.CREATE_TIME),"创建时间项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Customization.CREATE_TIME),"创建时间项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Customization.MODIFY_TIME),"修改时间项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Customization.MODIFY_TIME),"修改时间项字符必须为1-50个字符",1,50));
        validator.addRule(new StringMustBeRequired(model.getStr(Customization.STATUS),"转态项为必填信息"));
        validator.addRule(new StringLengthBetween(model.getStr(Customization.STATUS),"转态项字符必须为1-50个字符",1,50));
        validator.excute();

    }

    @Override
    public void beforAdd(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterAdd(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void beforUpdate(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterUpdate(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void beforQuery(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterQuery(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void beforDelete(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterDelete(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public String tableName() {
        return Customization.dao.tableName();
    }

    @Override
    public void builderSQLExpected(Model<?> model, QueryConstructor queryConstruct, Kv kv) {

    }
}